<?php
/*

 All rights Reserved, Designed By www.youyacao.com
 @Description:转账
 @author:成都市一颗优雅草科技有限公司
 @version 优雅草松鼠聚合直播系统
 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
 正版系统查询系统 zhengbancha.youyacao.com

*/

namespace app\admin\controller;

use \think\Db;

class Trade extends Base
{
    public function orderlist(){
        $user = $this->user;
        $db = Db::name("orders");

        if(input("type") == 1){
            $db = $db->where("payed_time",0);
        }

        $keyword = input("keyword");
        if(strlen($keyword)){
            $db = $db->where("order_no",$keyword);
        }

        $db = $db->order("id","desc");
        if($user['user_type'] == 'admin'){
            $list = $db->paginate(10);
        }else{
            $list = $db->where(function ($query) {
                $query->where("user_id", $this->user['id'])->whereOr("payuser_id", $this->user['id']);
            })->paginate(10);
        }

        $list->each(function ($item,$key){
            $item['need_money'] = number_format($item['need_money'],2);
            $item['payed_money'] = number_format($item['payed_money'],2);
            $item['type'] =  $item['type'] == 1 ? '系统操作' : ($item['type'] == 2 ? '转账支付' : '购买卡密');
            $item['info'] = $item['payuser_id'] == $this->user['id'] ?  '系统调节账户' : $item['info'];
            $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
            $item['payed_time'] = $item['payed_time'] ? date('Y-m-d H:i:s',$item['payed_time']) : '未支付';
            return $item;
        });
        $this->success($list);
    }
}
